
import java.io.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by 李晓容 on 2017/12/31.
 */

public class Check {
    public static void main(String[] args) {
        String WorkUrl = "";
        List<Student> students= new LinkedList<>();
        System.out.println("输入正确的命令：");//指定学生名单+指定文件夹 + 查询查漏
        while (true){
            int m= Integer.parseInt(new Scanner(System.in).next());
            switch (m){
                case 4:
                    System.out.println("学生名单(txt格式)" +
                            "提交作业所在的文件夹" +
                            "查询查漏");
                case 3:
                    check(students,WorkUrl);
                    break;
                case 2:
                    String s= new Scanner(System.in).next();
                    if (s!=null&&!s.equals(" ")){
                        WorkUrl = s;
                        System.out.println("成功");
                    }

                case 1:
                    String s1= new Scanner(System.in).next();
                    students= setStudentList(s1);
                    System.out.println("成功");

                default:
                    System.out.println("命令错误！");
            }
            System.out.println("请输入您的命令：");
        }
    }


    public  static List<Student> setStudentList(String url){
        List<Student> ss=new LinkedList<>();
        try {
            BufferedReader reader= new BufferedReader(new FileReader(url));
            String temp = null;
            while ((temp= reader.readLine())!=null){
                String[] temp1= temp.split("\\s");
                Student student= new Student();
                student.setSno(Integer.parseInt(temp1[0]));
                student.setName(temp1[1]);
                ss.add(student);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return ss;
    }

    public static void check(List<Student> s1,String workUrl){
        int size=0;
        if (s1.size()==0||workUrl.equals("")){
            System.out.println("指定文件夹！");
        }else {
            File file= new File(workUrl);
            String[] workNames= file.list();
            for(int i=0;i<workNames.length;i++){
                Pattern p = Pattern.compile("(\\d{10})");
                Matcher m= p.matcher(workNames[i]);
                String tt="";
                while (m.find()){
                    tt=m.group(1);
                }
                System.out.println("班级总人数:"+s1.size()+";已交:"+size+"人;");
                if (s1.size()>=size){
                    System.out.println("还有" + (s1.size()-size)+"人未交。");
                }
                for (Student s:s1){
                    if (s.isFlag()){
                        System.out.println("学号："+s.getSno()+"姓名："+s.getName());
                    }
                }
            }
        }

    }
}

